00001 /* 00002 * Copyright (c) 2013 Battelle Memorial Institute 00003 * Licensed under modified BSD License. A copy of this license can be found 00004 * in the LICENSE file in the top level directory of this distribution. 00005 */ 00006 // ------------------------------------------------------------- 00007 /** 00008 * @file pf_factory_module.hpp 00009 * @author Bruce Palmer 00010 * @date 2014-01-28 11:33:42 d3g096 00011 * 00012 * @brief 00013 * 00014 * 00015 */ 00016 // ------------------------------------------------------------- 00017 00018 #ifndef _pf_factory_module_h_ 00019 #define _pf_factory_module_h_ 00020 00021 #include "boost/smart_ptr/shared_ptr.hpp" 00022 #include "gridpack/network/base_network.hpp" 00023 #include "gridpack/factory/base_factory.hpp" 00024 #include "gridpack/applications/components/pf_matrix/pf_components.hpp" 00025 00026 namespace gridpack { 00027 namespace powerflow { 00028 00029 /// The type of network used in the powerflow application 00030 typedef gridpack::network::BaseNetwork<PFBus, PFBranch > PFNetwork; 00031 00032 class PFFactoryModule 00033 : public gridpack::factory::BaseFactory<PFNetwork> { 00034 public: 00035 /** 00036 * Struct for storing information on violations in contingency calculations 00037 */ 00038 struct Violation { 00039 bool line_violation; /* branch overload violation */ 00040 bool bus_violation; /* bus voltage violation */ 00041 int bus1; /* bus ID for voltage violations or from bus for branch violations */ 00042 int bus2; /* to bus ID for branch violations */ 00043 char tag[3]; /* 2 character identifier */ 00044 }; 00045 /** 00046 * Basic constructor 00047 * @param network: network associated with factory 00048 */ 00049 PFFactoryModule(NetworkPtr network); 00050 00051 /** 00052 * Basic destructor 00053 */ 00054 ~PFFactoryModule(); 00055 00056 /** 00057 * Create the admittance (Y-Bus) matrix 00058 */ 00059 void setYBus(void); 00060 00061 /** 00062 * Make SBus vector 00063 */ 00064 void setSBus(void); 00065 00066 /** 00067 * Update pg of specified bus element based on their genID 00068 * @param name 00069 * @param busID 00070 * @param genID 00071 * @param value 00072 */ 00073 // void updatePg(std::string &name, int busID, std::string genID, double value); 00074 void updatePg(int busID, std::string genID, double value); 00075 void updateQg(int busID, std::string genID, double value); 00076 00077 /** 00078 * Create the PQ 00079 */ 00080 void setPQ(void); 00081 00082 /** 00083 * Check for lone buses in the system. Do this by looking for buses that 00084 * have no branches attached to them or for whom all the branches attached 00085 * to the bus have all transmission elements with status false (the element 00086 * is off). Set status of bus to isolated so that it does not contribute to 00087 * powerflow matrix 00088 * @param stream optional stream pointer that can be used to print out IDs 00089 * of isolated buses 00090 * @return false if there is an isolated bus in the network 00091 */ 00092 bool checkLoneBus(std::ofstream *stream = NULL); 00093 00094 /** 00095 * Set lone buses back to their original status. 00096 */ 00097 void clearLoneBus(); 00098 00099 /** 00100 * Set voltage limits on all buses 00101 * @param Vmin lower bound on voltages 00102 * @param Vmax upper bound on voltages 00103 */ 00104 void setVoltageLimits(double Vmin, double Vmax); 00105 00106 /** 00107 * Check to see if there are any voltage violations in the network 00108 * @param area only check for voltage violations in this area 00109 * @return true if no violations found 00110 */ 00111 bool checkVoltageViolations(); 00112 bool checkVoltageViolations(int area); 00113 00114 /** 00115 * Check to see if there are any Q limit violations in the network 00116 * @param area only check for Q limit violations in this area 00117 * @return true if no violations found 00118 */ 00119 bool checkQlimViolations(); 00120 bool checkQlimViolations(int area); 00121 00122 /** 00123 * Clear changes that were made for Q limit violations and reset 00124 * system to its original state 00125 */ 00126 void clearQlimViolations(); 00127 00128 /** 00129 * Set "ignore" parameter on all buses with violations so that subsequent 00130 * checks are not counted as violations 00131 */ 00132 void ignoreVoltageViolations(); 00133 00134 /** 00135 * Clear "ignore" parameter on all buses 00136 */ 00137 void clearVoltageViolations(); 00138 00139 /** 00140 * Check to see if there are any line overload violations in 00141 * the network. The last call checks for overloads on specific lines. 00142 * @param area only check for voltage violations in this area 00143 * @param bus1 original index of "from" bus for branch 00144 * @param bus2 original index of "to" bus for branch 00145 * @param tags line IDs for individual lines 00146 * @param violations true if violation detected on branch, false otherwise 00147 * @return true if no violations found 00148 */ 00149 bool checkLineOverloadViolations(); 00150 bool checkLineOverloadViolations(int area); 00151 bool checkLineOverloadViolations(std::vector<int> &bus1, std::vector<int> &bus2, 00152 std::vector<std::string> &tags, std::vector<bool> &violations); 00153 00154 /** 00155 * Set "ignore" parameter on all lines with violations so that subsequent 00156 * checks are not counted as violations 00157 */ 00158 void ignoreLineOverloadViolations(); 00159 00160 /** 00161 * Clear "ignore" parameter on all lines 00162 */ 00163 void clearLineOverloadViolations(); 00164 00165 /** 00166 * Reinitialize voltages 00167 */ 00168 void resetVoltages(); 00169 00170 /** 00171 * Scale generator real power. If zone less than 1 then scale all 00172 * generators in the area 00173 * @param scale factor to scale real power generation 00174 * @param area index of area for scaling generation 00175 * @param zone index of zone for scaling generation 00176 */ 00177 void scaleGeneratorRealPower(double scale, int area, int zone); 00178 00179 /** 00180 * Scale load real power. If zone less than 1 then scale all 00181 * loads in the area 00182 * @param scale factor to scale load real power 00183 * @param area index of area for scaling load 00184 * @param zone index of zone for scaling load 00185 * @return false if there is not enough capacity to change generation 00186 * by requested amount 00187 */ 00188 void scaleLoadPower(double scale, int area, int zone); 00189 00190 /** 00191 * Return the total real power load for all loads in the zone. If zone 00192 * less than 1, then return the total load for the area 00193 * @param area index of area 00194 * @param zone index of zone 00195 * @return total load 00196 */ 00197 double getTotalLoadRealPower(int area, int zone); 00198 00199 /** 00200 * Return the current real power generation and the maximum and minimum total 00201 * power generation for all generators in the zone. If zone is less than 1 00202 * then return values for all generators in the area 00203 * @param area index of area 00204 * @param zone index of zone 00205 * @param total total real power generation 00206 * @param pmin minimum allowable real power generation 00207 * @param pmax maximum available real power generation 00208 */ 00209 void getGeneratorMargins(int area, int zone, double *total, double *pmin, 00210 double *pmax); 00211 00212 /** 00213 * Reset power of loads and generators to original values 00214 */ 00215 void resetPower(); 00216 00217 /** 00218 * Set parameters for real time path rating diagnostics 00219 * @param src_area generation area 00220 * @param src_zone generation zone 00221 * @param load_area load area 00222 * @param load_zone load zone 00223 * @param gen_scale scale factor for generation 00224 * @param load_scale scale factor for loads 00225 */ 00226 void setRTPRParams(int src_area, int src_zone, int load_area, 00227 int load_zone, double gen_scale, double load_scale); 00228 00229 /** 00230 * Return vector describing all violations 00231 * @return violation vector 00232 */ 00233 std::vector<Violation> getViolations(); 00234 00235 /** 00236 * Clear violation vector 00237 */ 00238 void clearViolations(); 00239 00240 /** 00241 * User rate B parameter for line overload violations 00242 * @param flag if true, use RATEB parameter 00243 */ 00244 void useRateB(bool flag); 00245 00246 private: 00247 00248 NetworkPtr p_network; 00249 std::vector<bool> p_saveIsolatedStatus; 00250 00251 std::vector<Violation> p_violations; 00252 00253 bool p_rateB; 00254 }; 00255 00256 } // powerflow 00257 } // gridpack 00258 #endif